﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page contentType="text/html; charset=utf-8"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>照片采集</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<script src="${pageContext.request.contextPath }/scripts/boot.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath }/scripts/LodopFuncs.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath }/scripts/readcard.js" type="text/javascript"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/js/ajaxfileupload.js"></script> 
<%
		response.setHeader("Pragma","no-cache");
		response.setHeader("Cache-Control","no-cache");
		response.setDateHeader("Expires",0);
 %>
<style type="text/css">
    html, body
    {
        font-size:12px;
        padding:0;
        margin:0;
        border:0;
        height:100%;
    } 
    
       #a {
	position:absolute;
	left:0px;
	top:0px;
	width:100%;
	height:12%;
	z-index:1;
}   

   #b {
	position:absolute;
	left:50px;
	top:15%;
	width:50%;
	height:50%;
	z-index:1;
}  

 #c {
	position:absolute;
	left:600px;
	top:15%;
	width:42%;
	height:50%;
	z-index:1;
}  

 #d {
	position:absolute;
	left:0px;
	top:70%;
	width:100%;
	height:20%;
	z-index:1;
}  
</style>
</head>
<body>
  <form id="form1" method="post">
    <div id="a">
    <fieldset  style="border:solid 1px #aaa;padding:3px;height:100%;">
     <legend>照片采集</legend>
      <table style="table-layout:fixed;width:60%;">
        <tr>
          <td style="width:15%;text-align:right;">社会保障卡号：</td>
          <td style="width:85%;"><input id="aac001" name="aac001" class="mini-textbox asLabel"  required="true"  onenter="onKeyEnter" maxlength="10" vtype="int;minLength:10" emptyText="请输入社会保障卡号" style="width:20%;"/>
          <a class="mini-button" id="card" name="card" onclick="getsfz" enabled="true" iconCls="icon-goto" style="width:100px;margin-right:20px;">读身份证</a>
   			<input name="aac002_name" class="mini-hidden" required="true" emptyText="请输入证件号" style="width:100%;"/>
      	  </td>
        </tr>
      </table>   
          </fieldset>
    </div>
      <div id="b" >
         <fieldset  style="border:solid 1px #aaa;padding:3px;height:100%;">
        <table style="table-layout:fixed;width:100%;height:100%;">
          <tr>          
            <td style="width:90px;white-space:nowrap;text-align:right;">姓名：</td>
            <td style="width:180px;"><input name="aac003" class="mini-textbox" inputStyle="background:rgb(241,241,243)" allowInput="false" readonly="readonly" style="width:80%;"/></td> 
              <td style="width:90px;white-space:nowrap;text-align:right;">性别：</td>
            <td style="width:180px;"><input name="aac004" class="mini-combobox" inputStyle="background:rgb(241,241,243)" allowInput="false" readonly="readonly" style="width:80%;"
             url="${pageContext.request.contextPath }/make.do?method=getaac004&lx=AAC004" valueField="aaa102" textField="aaa103" /> </td> 
          </tr>
          <tr>         
            <td style="width:90px;white-space:nowrap;text-align:right;">出生年月：</td>
            <td style="width:180px;"><input name="aac006" class="mini-datepicker" valueType="String"  inputStyle="background:rgb(241,241,243)" allowInput="false" readonly="readonly" style="width:80%;"/></td>
             <td style="width:90px;white-space:nowrap;text-align:right;">民族：</td>
            <td style="width:180px;"><input name="aac005" class="mini-combobox" inputStyle="background:rgb(241,241,243)" allowInput="false" readonly="readonly" style="width:80%;"
            url="${pageContext.request.contextPath }/zpcj.do?method=getaac005&lx=AAC005" valueField="aaa102" textField="aaa103" "/>
            </td>                    
          </tr>                
           <tr>
            <td style="width:90px;white-space:nowrap;text-align:right;">证件号：</td>
            <td colspan="3" style="width:270px;"><input name="aac002" class="mini-textbox" inputStyle="background:rgb(241,241,243)" allowInput="false" readonly="readonly" style="width:92%;"/></td>         
          </tr>
          <tr>
            <td style="width:90px;white-space:nowrap;text-align:right;">有无照片：</td>
            <td style="width:180px;"><input name="tmp001" class="mini-textbox" inputStyle="background:rgb(241,241,243)" allowInput="false" readonly="readonly" style="width:80%;"/></td>
            <td colspan="2" style="text-align:center;"><a class="mini-button">获取公安照片</a></td>
          </tr>
       </table>
     </fieldset>
      </div>
    <div id="c" style="text-align:center;" align="center">
      <table style="table-layout:fixed;width:100%;">
        <tr>
          <td style="width:20%;white-space:nowrap;text-align:right;">选择照片：</td>
          <td style="width:22%;"><input type="file"  name="file0" id="file0" multiple="multiple"  onchange="setImagePreview();"  style="width:100%;" /></td>         
        </tr>
        <tr>
          <td style="width:20%;white-space:nowrap;text-align:right;">照片：</td>
          <td style="width:22%;height:230px;white-space:nowrap;text-align:right;border:solid 1px #aaa;">
          <div id="localImag" align="center" style="height:100%;">
          <img id="preview" src="" style="display: block;" />
          </div>
          </td>
        </tr>
      </table>
    </div>
    <div id="d" style="text-align:center;padding:10px;">
      <a class="mini-button" id="onoks" iconCls="icon-ok"  onclick="onOk()" enabled="false" style="width:100px;margin-right:20px;">确认</a>
      <a class="mini-button" id="print" iconCls="icon-print"  enabled="false"  onclick="Preview()" style="width:100px;;margin-right:20px;">打印</a>
      <a class="mini-button" iconCls="icon-remove"  onclick="onReset" style="width:100px;margin-right:20px;">重置</a>     
    </div>
  </form>
<script type="text/javascript">
    mini.parse();
    var form = new mini.Form("form1");   
    

 function setImagePreview(avalue) {
   var aac001 = mini.getbyName("aac001").getValue().trim();      
       if(aac001=="")
       {
         mini.alert("社会保障卡号不能为空");
         var file = document.getElementById("file0");
         file.outerHTML=file.outerHTML.replace(/(value=\").+\"/i,"$1\"");     
         return;
       }

            //input

                var docObj = document.getElementById("file0");

			//img

                var imgObjPreview = document.getElementById("preview");

                //div

                var divs = document.getElementById("localImag");

                if (docObj.files && docObj.files[0]) {

                    //火狐下，直接设img属性

                    imgObjPreview.style.display = 'block';

                    imgObjPreview.style.width = '200px';

                    imgObjPreview.style.height = '227px';

                    //imgObjPreview.src = docObj.files[0].getAsDataURL();

                    //火狐7以上版本不能用上面的getAsDataURL()方式获取，需要一下方式

                   imgObjPreview.src = window.URL.createObjectURL(docObj.files[0]);

                } else {

                    //IE下，使用滤镜

                    docObj.select();

                    var imgSrc = document.selection.createRange().text;

                    var localImagId = document.getElementById("localImag");

                    //必须设置初始大小

                    localImagId.style.width = "200px";

                    localImagId.style.height = "227px";

                    //图片异常的捕捉，防止用户修改后缀来伪造图片

                    try {

                        localImagId.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)";

                        localImagId.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = imgSrc;

                    } catch(e) {

                        alert("您上传的图片格式不正确，请重新选择!");

                        return false;

                    }

                    imgObjPreview.style.display = 'none';

                    document.selection.empty();

                }

                return true;

            }

 			function getsfz() {
    			
				var info=readsfz();
                var sfz=info["sfzhm"];
            	 $.ajax({               
                    url: "/sbk/zpcj.do?method=getCard",
                    cache: false,
                    data:{sfz:sfz},
                    success: function (text) { 
                    	if(0==text)
						{
							alert("该人员未建档,请先登记该人员基础信息");
						}
						else
						{	
							  mini.getbyName("aac001").setValue(text);
							  onKeyEnter();
						}
                    	
                    }
				    });        
    		}
 
     
     function onKeyEnter()
        {
          var aac001 = mini.getbyName("aac001").getValue().trim();  
          if(aac001=="")
          {
             mini.alert("请输入社会保障卡号");
             return;
          }
          else{
          labelModel();                          
           $.ajax({               
                    url: "/sbk/zpcj.do?method=getunitdata",
                    cache: false,
                    data:{id:aac001},
                    success: function (text) { 
                        if(text == "1")
                        {
                          mini.alert("照片已采集");
                          return;
                        }
                        else
                        {
                          if(text == "null"){
                             mini.alert("无效社会保障卡号");
                             return;
                          }
                          else{
                             mini.get("onoks").setEnabled(true);            
                             var o = mini.decode(text);                                             
                             form.setData(o);
                             mini.getbyName("tmp001").setValue("无");   
                          }
                        }                                                              
                    }
                });        
        }
        }
        

        
function onOk()
{
           form.validate();
           if (form.isValid() == false) return;                
            var aac001 = mini.getbyName("aac001").getValue().trim();          
            var arrId=new Array(); 
            arrId[0] ="file0";
            var value = $("#file0").attr("value");       
            if(value == "" || value == null)
            {               
               mini.alert("请上传照片");
               return;            
            }   
            if(form.isValid()==true){
      	    mini.mask({el: document.body,cls: 'mini-mask-loading',html: '采集中...'});      	         	
            $.ajaxFileUpload({
            url:"${pageContext.request.contextPath }/pic.do?method=upload&key="+ aac001,
            type : 'post',
            secureuri : false,
            fileElementId : arrId,
            dataType : 'text',
            success: function (text) {           
                if(text.length>20){
                 text=text.substring(text.length-7,text.length-6);
                } 
                mini.unmask();                    
                if(text == "1")
                 {
                     mini.alert("照片采集成功");
                     labelModel();
                     var ui = document.getElementById("file0");
                     ui.style.display="none";
                     mini.get("print").setEnabled(true);
                     mini.get("onoks").setEnabled(false); 
                     return;                       
                 }
                 else if(text == "2")
                 {
                     mini.alert("照片大小不符");
                     onReset();
                 } 
                 else
                 {
                     mini.alert("照片采集失败");
                     onReset();                    
                 }                                          
           }         
            });
             }                 
}


   function labelModel() {
            var fields = form.getFields();                
                var c = fields[0];
                if (c.setReadOnly) c.setReadOnly(true);     //只读
                if (c.setIsValid) c.setIsValid(true);      //去除错误提示
                if (c.addCls) c.addCls("asLabel");          //增加asLabel外观
        }
        
         function inputModel() {
            var fields = form.getFields();           
                var c = fields[0];
                if (c.setReadOnly) c.setReadOnly(false);
                if (c.removeCls) c.removeCls("asLabel");          
            mini.repaint(document.body);
        }
        
 function onReset(e) {
   inputModel();
   var file = document.getElementById("file0");
   file.style.display="block";
   file.outerHTML=file.outerHTML.replace(/(value=\").+\"/i,"$1\""); 
   $("#preview").attr("src", "");
   form.reset();
   mini.get("print").setEnabled(false);
   mini.get("onoks").setEnabled(false); 	 	
		}
        
     var LODOP; //声明为全局变量 
	function Preview() {	
	CreateTwoFormPage();
	  	LODOP.PREVIEW();		
	}

function CreateTwoFormPage(){
LODOP=getLodop();
var aac001 = mini.getbyName("aac001").getValue().trim();
var aac003 = mini.getbyName("aac003").getValue().trim();
var aac004_name = mini.getbyName("aac004").getText().trim(); 
var aac002 = mini.getbyName("aac002").getValue().trim(); 
var aac005_name = mini.getbyName("aac005").getText().trim();
var aac006 = mini.getbyName("aac006").getValue().trim(); 
LODOP.PRINT_INITA(0,0,1180,641,"");
LODOP.ADD_PRINT_TEXT(92,159,120,24,aac001);
LODOP.SET_PRINT_STYLEA(0,"FontSize",13);
LODOP.ADD_PRINT_TEXT(92,401,111,24,aac003);
LODOP.SET_PRINT_STYLEA(0,"FontSize",13);
LODOP.ADD_PRINT_TEXT(93,617,96,23,aac004_name);
LODOP.SET_PRINT_STYLEA(0,"FontSize",13);
LODOP.ADD_PRINT_TEXT(149,160,342,24,aac002);
LODOP.SET_PRINT_STYLEA(0,"FontSize",13);
LODOP.ADD_PRINT_TEXT(146,614,108,25,aac005_name);
LODOP.SET_PRINT_STYLEA(0,"FontSize",13);
LODOP.ADD_PRINT_TEXT(194,161,570,23,aac006);
LODOP.SET_PRINT_STYLEA(0,"FontSize",13);
}        
</script>
</body>
</html>
